#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int n = nums.size();
        vector<int> qian(n);
        vector<int> hou(n);
        for (int i = 0; i < n; i++)
        {
            if (i == 0)
                qian[i] = 0;
            else
            {
                qian[i] = qian[i - 1] + nums[i - 1];
            }
        }
        for (int i = n - 1; i >= 0; i--)
        {
            if (i == n - 1)
                hou[i] = 0;
            else
            {
                hou[i] = hou[i + 1] + nums[i + 1];
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (qian[i] == hou[i])
                return i;
        }
        return -1;
    }
};